/**
 * Bakalarska prace - Inteligentni budik
 * @package sleepCatcher
 * @file FormSettingsInteligentSleep.cpp
 * @author Jan Pesava - xpesav00
 * @email xpesav00@stud.fit.vutbr.cz
 * @date 24. 12. 2011
 */

#include "forms/FormSettingsInteligentSleep.h"
#include "SCFormManager.h"
#include "SCSettings.h"
#include "SCTranslator.h"

FormSettingsInteligentSleep::FormSettingsInteligentSleep()
{
}

FormSettingsInteligentSleep::~FormSettingsInteligentSleep()
{
}

bool
FormSettingsInteligentSleep::Initialize()
{
	Construct(L"IDF_SETTINGS_INTELLIGENT_SLEEP");
	return true;
}

result
FormSettingsInteligentSleep::OnInitializing(void)
{
	result r = E_SUCCESS;

	this->pScrollPanelMaxAwakeTime = static_cast<ScrollPanel*>(GetControl("IDC_SCROLLPANEL_DIFFERENCE"));
	this->pValue0= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_0"));
	this->pValue5= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_5"));
	this->pValue10= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_10"));
	this->pValue15= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_15"));
	this->pValue20= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_20"));
	this->pValue25= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_25"));
	this->pValue30= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_30"));
	this->pValue40= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_40"));
	this->pValue50= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_50"));
	this->pValue60= static_cast<CheckButton*>(this->pScrollPanelMaxAwakeTime->GetControl("IDC_CHECKBUTTON_60"));

	this->pValue0->SetActionId(IDA_VALUE_0,IDA_VALUE_0);
	this->pValue5->SetActionId(IDA_VALUE_5, IDA_VALUE_5);
	this->pValue10->SetActionId(IDA_VALUE_10, IDA_VALUE_10);
	this->pValue15->SetActionId(IDA_VALUE_15, IDA_VALUE_15);
	this->pValue20->SetActionId(IDA_VALUE_20, IDA_VALUE_20);
	this->pValue25->SetActionId(IDA_VALUE_25, IDA_VALUE_25);
	this->pValue30->SetActionId(IDA_VALUE_30, IDA_VALUE_30);
	this->pValue40->SetActionId(IDA_VALUE_40, IDA_VALUE_40);
	this->pValue50->SetActionId(IDA_VALUE_50, IDA_VALUE_50);
	this->pValue60->SetActionId(IDA_VALUE_60, IDA_VALUE_60);

	this->pValue0->AddActionEventListener(*this);
	this->pValue5->AddActionEventListener(*this);
	this->pValue10->AddActionEventListener(*this);
	this->pValue15->AddActionEventListener(*this);
	this->pValue20->AddActionEventListener(*this);
	this->pValue25->AddActionEventListener(*this);
	this->pValue30->AddActionEventListener(*this);
	this->pValue40->AddActionEventListener(*this);
	this->pValue50->AddActionEventListener(*this);
	this->pValue60->AddActionEventListener(*this);

	//language
	this->SetTitleText(SCTranslator::GetText("IDS_SETTINGS_MAXAWAKETIME"));

	Footer* pFooter = this->GetFooter();
	FooterItem* pBack = new FooterItem();
	pBack->Construct(IDA_BUTTON_BACK);
	pBack->SetText(SCTranslator::GetText("IDS_ALARMS_BACK"));

	pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
	pFooter->AddItem(*pBack);

	pFooter->AddActionEventListener(*this);

	// Update Data
	//this->Update();

	delete pBack;

	return r;
}

result
FormSettingsInteligentSleep::OnTerminating(void)
{
	result r = E_SUCCESS;
	return r;
}

void
FormSettingsInteligentSleep::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
	switch(actionId)
	{
		case IDA_BUTTON_BACK:
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_0:
			SCSettings::SetAwakeTimeDifference(0);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_5:
			SCSettings::SetAwakeTimeDifference(5);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_10:
			SCSettings::SetAwakeTimeDifference(10);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_15:
			SCSettings::SetAwakeTimeDifference(15);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_20:
			SCSettings::SetAwakeTimeDifference(20);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_25:
			SCSettings::SetAwakeTimeDifference(25);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_30:
			SCSettings::SetAwakeTimeDifference(30);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_40:
			SCSettings::SetAwakeTimeDifference(40);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_50:
			SCSettings::SetAwakeTimeDifference(50);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_60:
			SCSettings::SetAwakeTimeDifference(60);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
	}
}

int
FormSettingsInteligentSleep::GetFormId()
{
	return SCFormManager::IDF_SETTINGS_INTELLIGENT_SLEEP;
}

void
FormSettingsInteligentSleep::SetChooseValue()
{
	this->pValue0->SetSelected(false);
	this->pValue5->SetSelected(false);
	this->pValue10->SetSelected(false);
	this->pValue15->SetSelected(false);
	this->pValue20->SetSelected(false);
	this->pValue25->SetSelected(false);
	this->pValue30->SetSelected(false);
	this->pValue40->SetSelected(false);
	this->pValue50->SetSelected(false);
	this->pValue60->SetSelected(false);

	switch(SCSettings::GetAwakeTimeDifference())
	{
		case 0:
			this->pValue0->SetSelected(true);
			break;
		case 5:
			this->pValue5->SetSelected(true);
			break;
		case 10:
			this->pValue10->SetSelected(true);
			break;
		case 15:
			this->pValue15->SetSelected(true);
			break;
		case 20:
			this->pValue20->SetSelected(true);
			break;
		case 25:
			this->pValue25->SetSelected(true);
			break;
		case 30:
			this->pValue30->SetSelected(true);
			break;
		case 40:
			this->pValue40->SetSelected(true);
			break;
		case 50:
			this->pValue50->SetSelected(true);
			break;
		case 60:
			this->pValue60->SetSelected(true);
			break;
	}
}

void
FormSettingsInteligentSleep::SetValue(int valueId)
{
	// Not implemented
}

void
FormSettingsInteligentSleep::Update()
{
	this->pScrollPanelMaxAwakeTime->ScrollToTop();
	this->SetChooseValue();
}

void
FormSettingsInteligentSleep::Redraw()
{
	this->Update();
	RequestRedraw(true);
}
